// components/count-down/index.js
Component({
  externalClasses: ["custom-class"],
  /**
   * 组件的属性列表
   */
  properties: {
    time: {
      type: Number,
      value: 60
    },
    sb: Boolean

  },

  /**
   * 组件的初始数据
   */
  data: {

  },
  lifetimes: {
    attached() {
      this.countDown()
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //倒计时
    countDown() {
      let timer = null
      // 停止定时器
      if (this.data.time === 0) return clearTimeout(timer)
      // 更新渲染
      this.setData({
        time: (this.data.time -= 1),
      })
      // 定时器
      timer = setTimeout(this.countDown.bind(this), 1000)
      //触发自定义事件 
      this.triggerEvent('change', this.data.time)
    }
  }
})